def invert_dict(dct):
    """Map values to keys.

    Return a new dictionary that maps the values of the given dictionary to
    their respective keys.
    """
    return dict((value, key) for (key, value) in dct.iteritems())


def module_to_dict(module):
    """Return the dictionary for a module, excluding internal members.

    Internal members have names that start with an underscore.
    """
    return dict((key, value) for (key, value) in module.__dict__.iteritems()
                if not key.startswith('_'))
